//
//  HelpCenterController.m
//  LiquorChain
//
//  Created by apple on 2019/1/3.
//  Copyright © 2019年 王冬. All rights reserved.
//

#import "HelpCenterController.h"
#import "YUFoldingTableView.h"
@interface HelpCenterController ()<YUFoldingTableViewDelegate>
@property (nonatomic, assign) YUFoldingSectionHeaderArrowPosition arrowPosition;
@property (nonatomic, weak) YUFoldingTableView *foldingTableView;
@property (nonatomic,strong) NSArray *titleArray;

@property (nonatomic, assign) NSInteger index;
@end

@implementation HelpCenterController

-(NSArray *)titleArray{
    if (!_titleArray) {
        _titleArray =[NSArray array];
    }
    return _titleArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"帮助中心";
    self.view.backgroundColor = BACKGROUNDCOLOR;
    // 创建tableView
    [self setupFoldingTableView];
    self.titleArray = @[@"新手操作注意事项有哪些?",@"新手操作注意事项有哪些1?",@"新手操作注意事项有哪些2?",@"新手操作注意事项有哪些3?",@"新手操作注意事项有哪些4?",@"新手操作注意事项有哪些5?"];
    // Do any additional setup after loading the view.
}

// 创建tableView
- (void)setupFoldingTableView
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    YUFoldingTableView *foldingTableView = [[YUFoldingTableView alloc] initWithFrame:CGRectMake(0, kNavBarHeight +15, SCREEN_WIDTH, SCREEN_HEIGHT-kNavBarHeight -kIPhoneXBottomHeight-15)];
    _foldingTableView = foldingTableView;
    
    [self.view addSubview:foldingTableView];
    foldingTableView.foldingDelegate = self;
    
    
    foldingTableView.foldingState = YUFoldingSectionStateFlod;
    // foldingTableView.sectionStateArray = @[@"1", @"0", @"0"];
    
}

#pragma mark - YUFoldingTableViewDelegate / required（必须实现的代理）
- (NSInteger )numberOfSectionForYUFoldingTableView:(YUFoldingTableView *)yuTableView
{
    return self.titleArray.count;
}
- (NSInteger )yuFoldingTableView:(YUFoldingTableView *)yuTableView numberOfRowsInSection:(NSInteger )section
{
    return 3;
}
- (CGFloat )yuFoldingTableView:(YUFoldingTableView *)yuTableView heightForHeaderInSection:(NSInteger )section
{
    return 50;
}
- (CGFloat )yuFoldingTableView:(YUFoldingTableView *)yuTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (UITableViewCell *)yuFoldingTableView:(YUFoldingTableView *)yuTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cellIdentifier";
    UITableViewCell *cell = [yuTableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text = @"新手操作注意事项有哪些新手操作注意事项有哪些新手操作注意事项有哪些新手操作注意事项有哪些新手操作注意事项有哪些新手操作注意事项有哪些新手操作注意事项有哪些";
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.textColor = [UIColor grayColor];
    cell.textLabel.font =[UIFont systemFontOfSize:13];
    
    return cell;
}
#pragma mark - YUFoldingTableViewDelegate / optional （可选择实现的）

- (NSString *)yuFoldingTableView:(YUFoldingTableView *)yuTableView titleForHeaderInSection:(NSInteger)section
{
    return self.titleArray[section];
}

- (void )yuFoldingTableView:(YUFoldingTableView *)yuTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [yuTableView deselectRowAtIndexPath:indexPath animated:YES];
}

// 返回箭头的位置
- (YUFoldingSectionHeaderArrowPosition)perferedArrowPositionForYUFoldingTableView:(YUFoldingTableView *)yuTableView
{
    // 没有赋值，默认箭头在左
    return self.arrowPosition ? :YUFoldingSectionHeaderArrowPositionRight;
}
//- (UIView *)yuFoldingTableView:(UITableView *)yuTableView viewForHeaderInSection:(NSInteger)section{
//    UIView *headView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
//    UIImageView *titleView =[[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 30, 30 )];
//    titleView.backgroundColor =[UIColor greenColor];
//    [headView addSubview:titleView];
//    UILabel *titleLabel =[[UILabel alloc]initWithFrame:CGRectMake(60, 10, 200, 30)];
//    titleLabel.text = @"新手操作注意事项有哪些?";
//    titleLabel.font =[UIFont systemFontOfSize:15];
//    [headView addSubview:titleLabel];
//    headView.backgroundColor =[UIColor whiteColor];
//
//    UIImageView *arrowImageView =[[UIImageView alloc]init];
//    [headView addSubview:arrowImageView];
//    arrowImageView.image =[UIImage imageNamed:@"YUFolding_arrow"];
//    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(10);
//        make.height.with.mas_equalTo(30);
//        make.right.mas_equalTo(-15);
//    }];
//    if (section == YUFoldingSectionStateFlod) {
//        if (self.arrowPosition == YUFoldingSectionHeaderArrowPositionRight) {
//            arrowImageView.transform = CGAffineTransformMakeRotation(-M_PI/2);
//        }else{
//            arrowImageView.transform = CGAffineTransformMakeRotation(M_PI/2);
//        }
//    } else {
//        if (self.arrowPosition == YUFoldingSectionHeaderArrowPositionRight) {
//            arrowImageView.transform = CGAffineTransformMakeRotation(M_PI/2);
//        }else{
//            arrowImageView.transform = CGAffineTransformMakeRotation(0);
//        }
//    }
//    return headView;
//}

@end
